﻿using System;
using System.IO;
namespace AutoUpdateEngine
{
    /// <summary>
    /// AppPart means any part of the application such as .config,.dll ,.exe...
    /// </summary>
    public class AppPart:ICloneable
    {
        public AppPart()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        string fileName, localDirect, oldFileName, remoteDirect;

        public string RemoteDirect
        {
            get { return remoteDirect; }
            set { remoteDirect = AdjustDirect(value); }
        }

        public string OldFileName
        {
            get { return oldFileName; }
            set { oldFileName = AdjustFileName(value); }
        }

        public string LocalDirect
        {
            get { return localDirect; }
            set { localDirect = AdjustDirect(value); }
        }

        public string FileName
        {
            get { return fileName; }
            set { fileName = AdjustFileName(value); }
        }

        public string GetRemoteFilePath()
        {
            return remoteDirect+fileName;
        }
        public string GetLocalFilePath()
        {
            return localDirect+ fileName;
        }
        public string GetLocalOldFilePath()
        {
            return localDirect+ oldFileName;
        }

        private string AdjustDirect(string direct)
        {
            if (!direct.EndsWith("\\"))
                return direct + "\\";
            else
                return direct;
        }
        private string AdjustFileName(string fileName)
        {
            if (fileName.StartsWith("\\"))
                return fileName.Remove(0, 1);
            else
                return fileName;
        }
        #region ICloneable 成员

        public object Clone()
        {
            AppPart part = new AppPart();
            part.fileName = this.fileName;
            part.oldFileName = this.oldFileName;
            part.localDirect = this.localDirect;
            part.remoteDirect = this.remoteDirect;

            return part;
        }

        #endregion
    }
}